package com.eleadmin.order.controller;

import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.common.core.web.BaseController;
import com.eleadmin.common.core.web.JsonResult;
import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.order.entity.Customer;
import com.eleadmin.order.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 *
 * 订报关行
 * @author : Doman
 * @date : 2023-02-13 15:50:11
 * @version ：1.0
 */

@Api(tags = "订报关行")
@RestController
@RequestMapping("/api/order/customBroker")
public class CustomBrokerController extends BaseController {

    @Autowired
    private CustomerService customerService;

    @PreAuthorize("hasAuthority('order:customBroker:list')")
    @ApiOperation("分页查询订报关行")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, Customer customer) throws Exception{
        return customerService.list(page, customer, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:customBroker:list')")
    @ApiOperation("查询全部订报关行")
    @GetMapping()
    public JsonResult list(Customer customer){
        return customerService.list(customer, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:customBroker:list')")
    @ApiOperation("根据id查询订报关行")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return customerService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:customBroker:save')")
    @OperationLog
    @ApiOperation(value ="添加订报关行")
    @PostMapping()
    public JsonResult save(@RequestBody Customer customer) {
        try {
            return customerService.saveCustomBroker(customer, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:customBroker:exam')")
    @OperationLog
    @ApiOperation(value ="审核订报关行")
    @PostMapping("examCustomBroker")
    public JsonResult examCustomBroker(@RequestBody Customer customer) {
        try {
            return customerService.examCustomer(customer, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:customBroker:update')")
    @OperationLog
    @ApiOperation(value ="修改订报关行")
    @PutMapping()
    public JsonResult update(@RequestBody Customer customer) {
        try {
            return customerService.update(customer, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:customBroker:remove')")
    @OperationLog
    @ApiOperation(value ="删除订报关行")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return customerService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }




}
